package com.zhou.day1;


import org.springframework.stereotype.Component;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPubSub;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author Mr.zhou
 */
@Component
public class JedisConfig extends JedisPubSub {

    @Override
    public void onMessage(String channel, String message) {
        Jedis jedis = new Jedis("127.0.0.1",6379);
        JedisConfig jedisConfig = new JedisConfig();
        jedis.subscribe(jedisConfig,"zhou");
        // 当订阅者收到消息 此方法会自动被调用
        System.out.println("订阅的频道为："+channel);
        System.out.println("收到的消息为："+message);
        System.out.println("时间为："+new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
    }

    public static void main(String[] args) {
        JedisConfig jedisConfig = new JedisConfig();
        int[] arr = new int[]{1,5,6,0,7,4,9,3};
        int[] index = new int[]{0,1,2,3,4,0,5,1,2,6,7};
        StringBuffer tel = new StringBuffer();
        for (int i:index) {
            tel.append(arr[i]);
        }
        System.out.println(tel);
    }
}
